<template>
	<view class="wrap">
		<u-form class="form" :model="model" :rules="rules" ref="uForm" :label-position="labelPosition">
			<u-form-item label="提醒类型" prop="remindType" label-width="180" :required="true">
				<js-select v-model="model.remindType" dict-type="wechat_remind_type" itemLabel="dictValue"
					itemValue="dictKey" placeholder="请选择提醒类型" :disabled="disabled"></js-select>
			</u-form-item>
			<u-form-item ref="uFormItemSummary" :label="summaryPropLabel" prop="summary" label-width="180" :label-position="summaryPropLabelPosition" :required="true">
				<u-input v-model="model.summary" :type="summaryPropInputType" :placeholder="'请输入' + summaryPropLabel" height="100" maxlength="500" :disabled="disabled"/>
			</u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule" ref="uFormItemUserList" label="参与人" prop="userList" label-width="180" label-position="top">
				<view>
					<scroll-view :scroll-top="scrollTop" :scroll-y="scrollY" :class="{'scroll-Y': isScroll}"
						@scroll="scroll">
						<u-tag :text="item.name" :type="uTagProps.type" v-for="(item, index) in model.userList" 
							:key="item.userId" :index="item.userId" :shape="uTagProps.shape" 
							:closeable="uTagProps.closeable" :mode="uTagProps.mode" 
							:size="uTagProps.size" @close="doDeleteUser" class="uTagStyle"></u-tag>
					</scroll-view>
				</view>
				<u-button v-if="!isViewMode" slot="right" type="success" size="mini" @click="chooseGroupUsers" style="">选择成员</u-button>
				<js-choose-user-popup v-if="useInitChooseUserComp" ref="chooseGroupUsers" @submit="useGroupUsersSelected"
					:mode="popupMeetingUsers.mode" :multiple="popupMeetingUsers.multiple"
					:action="chooseUserUrl" :default-selected-user-list = "defaultGroupMemberUserList"></js-choose-user-popup>
			</u-form-item>
			<u-form-item :label="startTimePropLabel" prop="startTime" label-width="180" :required="true">
				<view style="width: 100%;">
					<u-input v-model="model.startTime==''?getStartTimePropLabel:model.startTime" :type="disabled?'input':'select'" @click="uPickerStartTime.show = !disabled" :disabled="disabled"></u-input>
					<u-picker v-model="uPickerStartTime.show" :mode="uPickerStartTime.mode" :params="uPickerStartTime.params" @confirm="confirm4StartTime"></u-picker>
				</view>
			</u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule && !showEndTime" label="持续时长" prop="duration" label-width="180" :required="true">
				<js-select v-model="duration" dict-type="wechat_living_duration" itemLabel="dictValue"
					itemValue="dictKey" placeholder="请选择持续时长" :disabled="disabled" @input="durationChange"></js-select>
			</u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule && showEndTime" ref="uFormItemEndTime" label="结束时间" prop="endTime" label-width="180" :required="true">
				<view style="width: 100%;">
					<u-input v-model="model.endTime == ''?'请选择结束时间':model.endTime" :type="disabled?'input':'select'" @click="uPickerEndTime.show = !disabled" :disabled="disabled"></u-input>
					<u-picker v-model="uPickerEndTime.show" :mode="uPickerEndTime.mode" :params="uPickerEndTime.params" @confirm="confirm4EndTime"></u-picker>
				</view>
			</u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule" label="描述" prop="description" label-width="180" label-position="top">
				<u-input v-model="model.description" type="textarea" placeholder="请输入描述" height="100" maxlength="500" :disabled="disabled"/>
			</u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule" label="日程地址" prop="location" label-width="180">
				<u-input v-model="model.location" placeholder="请输入日程地址" type="text" maxlength="64" style="text-align: left;" :disabled="disabled"></u-input>
			</u-form-item>
			<u-form-item label="是否要提醒" prop="isRemind" label-width="auto" :required="true">
				<u-switch v-model="isRemindChecked" active-value="1" inactive-value="0" @change="isRemindChange" :disabled="disabled"></u-switch>	
			</u-form-item>
			<u-form-item v-if="showRemindBeforeEventSecs" :label="remindBeforeEventSecsPropLabel" prop="remindBeforeEventSecs" label-width="auto">
				<js-select v-model="model.remindBeforeEventSecs" dict-type="wechat_remind_before_event_secs" itemLabel="dictValue"
					itemValue="dictKey" :placeholder="'请选择' + remindBeforeEventSecsPropLabel" :disabled="disabled"></js-select>
			</u-form-item>
			<!-- 预留空一个u-form-item 解决相邻2个js-select数据加载问题 -->
			<u-form-item style="display: none;"></u-form-item>
			<u-form-item v-if="showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay" label="是否重复日程" prop="isRepeat" label-width="auto" :required="true">
				<u-switch v-model="isRepeatChecked" active-value="1" inactive-value="0" @change="isRepeatChange" :disabled="disabled"></u-switch>	
			</u-form-item>
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showRepeatType" label="重复类型" prop="repeatType" label-width="180" :required="true">
				<js-select v-model="model.repeatType" dict-type="wechat_schedule_repeat_type" itemLabel="dictValue"
					itemValue="dictKey" placeholder="请选择重复类型" :disabled="disabled"></js-select>
			</u-form-item>
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showRepeatType" ref="uFormItemRepeatUntil" label="重复结束时间" prop="repeatUntil" label-width="auto" :required="false">
				<view style="width: 100%;">
					<u-input v-model="model.repeatUntil == '' ? '请选择重复结束时间': model.repeatUntil" :type="disabled?'input':'select'" @click="uPickerRepeatUntil.show = !disabled" :disabled="disabled"></u-input>
					<u-picker v-model="uPickerRepeatUntil.show" :mode="uPickerRepeatUntil.mode" :params="uPickerRepeatUntil.params" @confirm="confirm4RepeatUntil"></u-picker>
				</view>
			</u-form-item>
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showFrequency" label="自定义频率" prop="frequency" label-width="180" :required="true">
				<js-select v-model="model.frequency" dict-type="wechat_schedule_frequency" itemLabel="dictValue"
					itemValue="dictKey" placeholder="请选择自定义频率" :disabled="disabled"></js-select>
			</u-form-item>
			<!-- 按天、周、月、年-->
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showRepeatInterval" label="重复间隔" prop="repeatInterval" label-width="180" :required="true">
				<js-select v-model="model.repeatInterval" :items="repeatIntervalOptions" itemLabel="label"
					itemValue="value" placeholder="请选择频率" :disabled="disabled"></js-select>
			</u-form-item>
			<!-- 按周 -->
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showFrequencyByDaysOfWeek" label="每周周几重复" prop="repeatDayOfWeek" label-width="180">
				<u-checkbox-group @change="repeatDayOfWeekGroupChange" :width="checkboxGroupProps.width" :wrap="checkboxGroupProps.wrap" :disabled="disabled">
					<u-checkbox v-model="item.checked" v-for="(item, index) in repeatDayOfWeekOptions" :key="index" :name="item.value">{{ item.label }}</u-checkbox>
				</u-checkbox-group>		
			</u-form-item>
			<!-- 按月 -->
			<u-form-item v-if="(showSpecificPropsOfSchedule || showSpecificPropsOfRemind || showSpecificPropsOfMemorialDay) && showFrequencyByDaysOfMonth" label="每月哪几天重复" prop="repeatDayOfMonth" label-width="180">
				<u-checkbox-group @change="repeatDayOfMonthGroupChange" :width="checkboxGroupProps.width" :wrap="checkboxGroupProps.wrap" :disabled="disabled">
					<u-checkbox v-model="item.checked" v-for="(item, index) in repeatDayOfMonthOptions" :key="index" :name="item.value">{{ item.label }}</u-checkbox>
				</u-checkbox-group>		
			</u-form-item>
			<!-- <u-form-item label="附件" prop="attach" label-width="180" label-position="top">
				<wechat-upload ref="attachUpload" :action="'/api/blade-resource/oss/endpoint/put-file'" :file-list="attachFileList" upload-text="点击上传" accept="file" :max-count="upload.maxCount" :deletable="upload.deletable"></wechat-upload>
			</u-form-item> -->
		</u-form>
		<slot name="footerBtns">
			<view style="display: flex;flex-direction: row;">
				<u-button v-if="!isViewMode" class="btn" style="width: 50%;margin-right: 10rpx;" type="primary" @click="submit">保存</u-button>
				<u-button class="btn" style="width: 50%;" @click="cancel">
					{{isViewMode ? '返回' : '取消'}}
				</u-button>
			</view>
		</slot>
	</view>
</template>
<script>
	import WechatUpload from '@/pages/wechat/wechat-upload.vue'
	
	/**
	 * @property {Stringr | Number} id 主键ID
	 * @property {Stringr} modeProp 模式（view、eidit、add）外部传入的属性
	 */
	export default {
		components: {
			WechatUpload
		},
		props: {
			id: {
				type: [String,Number],
				default: ''
			},
			modeProp: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				model: {
					remindType: '',
					summary: '',
					attendees: '',
					startTime: '',
					endTime: '',
					description: '',
					location: '',
					userList: [],
					isRemind: '',
					remindBeforeEventSecs: '',
					isRepeat: '',
					repeatType: '',
					repeatUntil: '',
					isCustomRepeat: '0',
					frequency: '',
					repeatDayOfWeek: '',
					repeatDayOfMonth: '',
					attach: ''
				},
				isModelLoadedFlag: false,
				// 操作模式：view、add、edit
				mode: '',
				// 默认3600秒（1个小时）
				duration: '3600',
				uPickerStartTime: {
					show: false,
					mode: 'time',
					params: {
						year: true,
						month: true,
						day: true,
						hour: true,
						minute: true,
						second: true
					}
				},
				uPickerEndTime: {
					show: false,
					mode: 'time',
					params: {
						year: true,
						month: true,
						day: true,
						hour: true,
						minute: true,
						second: true
					}
				},
				uPickerRepeatUntil: {
					show: false,
					mode: 'time',
					params: {
						year: true,
						month: true,
						day: true,
						hour: true,
						minute: true,
						second: true
					}
				},
				uTagProps: {
					mode: 'light',
					type: 'primary',
					size: 'default',
					shape: 'square',
					closeable: true
				},
				isViewMode: false,
				summaryPropLabel: '标题',
				summaryPropInputType: 'textarea',
				summaryPropLabelPosition: 'top',
				startTimePropLabel: '开始时间',
				remindBeforeEventSecsPropLabel: '开始前多久提醒',
				//是否显示~提醒类型（日程）的特有属性
				showSpecificPropsOfSchedule: true,
				//是否显示~提醒类型（提醒）的特有属性
				showSpecificPropsOfRemind: false,
				//是否显示~提醒类型（纪念日）的特有属性
				showSpecificPropsOfMemorialDay: false,
				//是否显示~结束时间表单项
				showEndTime: false,
				//是否显示~开始前多久提醒
				showRemindBeforeEventSecs: false,
				showRepeatType: false,
				//是否显示~自定义频率
				showFrequency: false,
				//是否显示~重复间隔
				showRepeatInterval: false,
				//是否显示~每周周几重复
				showFrequencyByDaysOfWeek: false,
				//是否显示~每月哪几天重复
				showFrequencyByDaysOfMonth: false,
				labelPosition: 'left',
				disabled: true,
				rules: {
					remindType: [{
						required: true,
						message: '请选择提醒类型',
						trigger: 'change'
					}],
					summary: [{
						validator: (rule, value, callback) => {
							if(value){
								callback();
							}else{
								let message = '请输入' + this.summaryPropLabel;
								callback(new Error(message));
							}
						},
						trigger: 'blur'
					}],
					startTime: [
						{
							validator: (rule, value, callback) => {
								if(value){
									callback();
								}else{
									let message = '请选择' + this.startTimePropLabel;
									callback(new Error(message));
								}
							},
							trigger: 'change'
						}
					],
					duration: [{
						validator: (rule, value, callback) => {
							// duration不是model对象的属性，所以value没有值
							let validateResult = true;
							let duration = this.duration;
							if(!this.showEndTime && !duration){
								validateResult = false;
							}
							return validateResult;
						},
						message: '请选择持续时长',
						trigger: 'change'
					}],
					endTime: [
						{
							required: true,
							message: '请选择结束时间',
							trigger: 'change',
						},
						{
							validator: (rule, value, callback) => {
								if(this.model.remindType != '1'){
									//非日程则不检验
									callback();
								}
								let endTime = new Date(value);
								if(this.model.startTime){
									let startTime = new Date(this.model.startTime);
									if(endTime.getTime() < startTime.getTime()){
										callback(new Error('结束时间不能小于开始时间'));
									}else{
										callback();
									}
								}else{
									callback(new Error('请先选择开始时间'));
								}
							},
							trigger: 'change'
						}
					],
					// 验证规则的type属性默认类型为string，而在详情接口返回中liveType是数值，
					// 发生'liveType is not a string'，从而在编辑页面中提示检验不通过。
					// 解决方法指定type: 'number'，或validator自定义方法。
					repeatType: [{
						validator: (rule, value, callback) => {
							return (value || value === 0) ? true : false;
						},
						message: '请选择重复类型',
						trigger: 'change'
					}],
					// 重复结束时间非必填
					// repeatUntil: [{
					// 	required: true,
					// 	message: '请选择重复结束时间',
					// 	trigger: 'change'
					// }],
					frequency: [{
						required: true,
						type: 'number',
						message: '请选择自定义频率',
						trigger: 'change'
					}],
					repeatInterval: [{
						required: true,
						type: 'number',
						message: '请选择重复间隔',
						trigger: 'change'
					}]
				},
				labelPosition: 'left',
				chooseUserUrl: '/api/blade-system/user/user-list-by-dept-type',
				popupMeetingUsers: {
					show: false,
					mode: "bottom",
					multiple: true,
				},
				isScroll: true,
				scrollTop: 0,
				scrollY: true,
				old: {
					scrollTop: 0
				},
				checkboxGroupProps: {
					width: 'auto',
					wrap: false
				},
				dictDataOptions: {
					'wechatYesNo': []
				},
				repeatIntervalOptions: [],
				//每周周几重复
				repeatDayOfWeekOptions: [],
				//每月哪几天重复
				repeatDayOfMonthOptions: [],
				//已有的附件列表
				attachFileList: [],
				upload: {
					deletable: true,
					maxCount: 5,
					maxSize: 10 * 1024 * 1024
				},
				isRemindChecked: false,
				isRepeatChecked: false
			};
		},
		computed: {
			/**
			 * 返回是否初始化选择用户组件的标识
			 * 解决父组件将请求回来的数据传递给子组件的延迟问题
			 */
			useInitChooseUserComp: function(){
				let useInit = false;
				if(this.mode === 'add' || (this.mode === 'edit' && this.isModelLoadedFlag)){
					useInit = true;
				}
				return useInit;
			},
			defaultGroupMemberUserList: function(){
				let userList = this.model.userList.map(user => {
					return {
						id: user.userId,
						name: user.name,
					}
				});
				return userList;
			},
			getStartTimePropLabel: function() {
				return '请选择' + this.startTimePropLabel;
			}
		},
		watch: {
			'model.remindType': function(val,oldVal){
				// console.log("model.remindType,val:%s,oldVal:%s",val,oldVal);
				// remindTyp~1(日程)、2(提醒)、3(待办)、4(生日)、5(纪念日)
				// 为了逻辑清晰易整改，后续的话还是要细化为一个个对应的组件
				if(val == '1'){
					this.showSpecificPropsOfSchedule = true;
					this.summaryPropLabel = '标题';
					this.summaryPropInputType = 'textarea';
					this.summaryPropLabelPosition = 'top';
					this.startTimePropLabel = '开始时间';
					this.remindBeforeEventSecsPropLabel = '开始前多久提醒';
				}else{
					if(val == '2' || val == '3' || val == '5'){
						this.summaryPropLabel = '内容';
						this.summaryPropInputType = 'textarea';
						this.summaryPropLabelPosition = 'top';
						this.startTimePropLabel = '提醒日期';
						this.remindBeforeEventSecsPropLabel = '提醒日期开始前';
					}
					if(val == '4'){
						this.summaryPropLabel = '姓名';
						this.summaryPropInputType = 'input';
						this.summaryPropLabelPosition = 'left';
						this.startTimePropLabel = '提醒日期';
						this.remindBeforeEventSecsPropLabel = '提醒日期开始前';
					}
					this.showSpecificPropsOfSchedule = false;
				}
				if(val == '2'){
					this.showSpecificPropsOfRemind = true;
				}else{
					this.showSpecificPropsOfRemind = false;
				}
				if(val == '5'){
					this.showSpecificPropsOfMemorialDay = true;
				}else{
					this.showSpecificPropsOfMemorialDay = false;
				}
				if(this.$refs.uFormItemSummary){
					this.$refs.uFormItemSummary.$emit('on-form-change');
				}
				this.clearRemindTypeRelRequiredFieldProps(val,oldVal);
			},
			'model.userList': function(val,oldVal){
				// 通知将当前的值发送到 userList的u-form-item组件中进行校验
				if(this.$refs.uFormItemUserList){
					this.$refs.uFormItemUserList.$emit('on-form-change', val);
				}
			},
			'model.isRemind': function(val,oldVal){
				if(val == '1'){
					this.isRemindChecked = true;
					this.showRemindBeforeEventSecs = true;
				}else if(val == '0'){
					this.isRemindChecked = false;
					this.showRemindBeforeEventSecs = false;
				}
			},
			'model.isRepeat': function(val,oldVal){
				// console.log("model.isRepeat,val:%s,oldVal:%s",val,oldVal);
				if(val == '1'){
					this.isRepeatChecked = true;
					this.showRepeatType = true;
				}else if(val == '0'){
					this.isRepeatChecked = false;
					this.showRepeatType = false;
					//重置model.repeatType
					this.model.repeatType = '';
				}
			},
			'model.repeatType': function(val,oldVal) {
				// console.log("model.repeatType,val:%s,oldVal:%s",val,oldVal);
				if(val == '99'){
					//自定义
					this.showFrequency = true;
					this.model.isCustomRepeat = '1';
				}else{
					this.showFrequency = false;
					//重置model.frequency
					this.model.frequency = '';
					this.model.isCustomRepeat = '0';
				}
			},
			'model.frequency': function(val,oldVal) {
				console.log("model.frequency,val:%s,oldVal:%s",val,oldVal);
				let repeatIntervalOptions = this.repeatIntervalOptions;
				//查看或修改返回的model.frequency会为0(每日)，类型为number的情况
				if(val || val === 0){
					this.showRepeatInterval = true;
				}else{
					this.showRepeatInterval = false;
					//重置repeatIntervalOptions
					repeatIntervalOptions.splice(0,repeatIntervalOptions.length);
					this.showFrequencyByDaysOfWeek = false;
					this.showFrequencyByDaysOfMonth = false;
					return;
				}
				if(val == '0'){//按天
					repeatIntervalOptions.splice(0,repeatIntervalOptions.length);
					for (let i = 1; i <= 365; i++) {
					  this.repeatIntervalOptions.push({ label: i + '天', value: i + '' });
					}
					this.showFrequencyByDaysOfWeek = false;
					this.showFrequencyByDaysOfMonth = false;
				}else if(val == '1'){//按周
					repeatIntervalOptions.splice(0,repeatIntervalOptions.length);
					for (let i = 1; i <= 52; i++) {
						repeatIntervalOptions.push({ label: i + '周', value: i + '' });
					}
					this.showFrequencyByDaysOfWeek = true;
					this.showFrequencyByDaysOfMonth = false;
				}else if(val == '2'){//按月
					repeatIntervalOptions.splice(0,repeatIntervalOptions.length);
					for (let i = 1; i <= 12; i++) {
						repeatIntervalOptions.push({ label: i + '个月', value: i + '' });
					}
					this.showFrequencyByDaysOfWeek = false;
					this.showFrequencyByDaysOfMonth = true;
				}else if(val == '5'){//按年
					repeatIntervalOptions.splice(0,repeatIntervalOptions.length);
					for (let i = 1; i <= 12; i++) {
						repeatIntervalOptions.push({ label: i + '年', value: i + '' });
					}
					this.showFrequencyByDaysOfWeek = false;
					this.showFrequencyByDaysOfMonth = false;
				}
			},
			'model.startTime': function(val,oldVal){
				if(val && this.$refs.uFormItemEndTime){
					this.$refs.uFormItemEndTime.$emit('on-form-change');
				}
			}
		},
		beforeCreate(){
			// console.log("0.beforeCreate...");
		},
		onLoad(params) {
			// console.log("1.onLoad...");
			this.initData(params);
		},
		created() {
			// console.log("2.created...");
			if(this.id){
				// 场景适用于当前组件在弹出层中的展示
				let params = {
					id: this.id
				};
				if(this.modeProp){
					params.mode = this.modeProp;
				}
				this.initData(params);
			}
		},
		onReady() {
			// console.log("3.onReady...");
			this.$refs.uForm.setRules(this.rules);
		},
		beforeMount(){
			// console.log("beforeMount...");
		},
		mounted(){
			// console.log("4.mounted...");
		},
		methods: {
			initData(params){
				let vm = this;
				this.mode = params.mode;
				if (params.id) {
					this.showEndTime = true;
					if (this.mode == "view") {
						this.disabled = true;
						this.isViewMode = true;
						this.uTagProps.closeable = false;
					} else {
						this.disabled = false;
						this.isViewMode = false;
						this.uTagProps.closeable = true;
					}
					this.$u.api.wechat.wechatSchedule.detail({
						id: params.id
					}).then(res => {
						Object.assign(vm.model, res.data);
						//由于remindType的检验规则中type默认为string类型，则需将number类型转为string
						vm.model.remindType = vm.model.remindType + '';
						vm.isModelLoadedFlag = true;
						//方法initData与initRepeatDayOptions异步情况
						vm.initRepeatDayOptions();
						vm.initDefaultAttachFileList();
						
					});
				} else {
					this.disabled = false;
					this.showEndTime = false;
					this.initRepeatDayOptions();
					this.model.isRemind = "0";
					//初始为日程
					this.model.remindType = "1";
					this.model.isRepeat = "0";
				}
			},
			initRepeatDayOptions() {
				// 处理 repeatDayOfWeek
				let repeatDayOfWeek2Array = [];
				if(this.model.repeatDayOfWeek){
					repeatDayOfWeek2Array = this.model.repeatDayOfWeek.split(',');
				}
				const daysOfWeek = ['一', '二', '三', '四', '五', '六', '日'];
				for (var i = 1; i <= 7; i++) {
					let checked = repeatDayOfWeek2Array.some(element => element == i);
					this.repeatDayOfWeekOptions.push({ 
						label: '周' + daysOfWeek[i - 1], 
						value: i + '',
						checked: checked
					});
				}
				
				// 处理 repeatDayOfMonth
				let repeatDayOfMonth2Array = [];
				if(this.model.repeatDayOfMonth){
					repeatDayOfMonth2Array = this.model.repeatDayOfMonth.split(',');
				}
				for (let i = 1; i <= 31; i++) {
					let checked = repeatDayOfMonth2Array.some(element => element == i);
					this.repeatDayOfMonthOptions.push({ 
						label: i + '号', 
						value: i + '' ,
						checked: checked
					});
				}
			},
			initWechatYesNo(){
				let vm = this;
				this.$u.api.dictBizData({
					code: 'wechat_yes_no'
				}).then(res => {
					let optionList = [];
					res.data.forEach((item) => {
						optionList.push({
							'label': item.dictValue,
							'value': item.dictKey
						});
					})
					this.dictDataOptions.wechatYesNo = optionList;
				});
			},
			durationChange(val){
				//自定义时间
				if(val == 4){
					this.model.endTime = '';
					this.showEndTime = true;
					//将回调延迟到下次 DOM 更新循环之后执行
					this.$nextTick(() => {
						if(this.$refs.uFormItemEndTime){
							this.$refs.uFormItemEndTime.$emit('on-form-change')
						}
					});
				}
			},
			initDefaultAttachFileList() {
				let attach = this.model.attach;
				if(attach){
					let attachList = attach.split(',');
					attachList.forEach(element => {
						this.attachFileList.push({
							url: element
						});
					})
				}
			},
			getPickerResult(e,params){
				let pickerResult = '';
				if (params.year) {
					pickerResult += e.year;
				}
				if (params.month) {
					pickerResult += '-' + e.month;
				}
				if (params.day) {
					pickerResult += '-' + e.day;
				}
				if (params.hour) {
					pickerResult += ' ' + e.hour;
				}
				if (params.minute) {
					pickerResult += ':' + e.minute;
				}
				if (params.second) {
					pickerResult += ':' + e.second;
				}
				return pickerResult;
			},
			confirm4StartTime(e) {
				this.model.startTime = this.getPickerResult(e,this.uPickerStartTime.params);
				this.uPickerStartTime.show = false;
			},
			confirm4EndTime(e) {
				this.model.endTime = this.getPickerResult(e,this.uPickerEndTime.params);
				this.uPickerEndTime.show = false;
			},
			confirm4RepeatUntil(e) {
				this.model.repeatUntil = this.getPickerResult(e,this.uPickerRepeatUntil.params);
				this.uPickerRepeatUntil.show = false;
			},
			chooseGroupUsers() {
				this.$refs.chooseGroupUsers.open();
				this.$refs.chooseGroupUsers.setDefaultSelectedUserList(this.defaultGroupMemberUserList);
			},
			useGroupUsersSelected() {
				let groupUsers = this.$refs.chooseGroupUsers.getData();
				if (groupUsers.length > 0) {
					this.model.userList = [];
				}
				groupUsers.forEach((element) => {
					this.model.userList.push({
						"name": element.name,
						"userId": element.id
					});
				});
				this.$refs.chooseGroupUsers.close();
			},
			scroll: function(e) {
				this.old.scrollTop = e.detail.scrollTop
			},
			doDeleteUser: function(userId) {
				this.model.userList = this.model.userList.filter(user => userId != user.userId);
				this.$refs.chooseGroupUsers.$emit('remove-selected-user-by-id',userId);
			},
			getAttachFileList() {
				let files = this.$refs.attachUpload.getFileList();
				let fileUrlList = [];
				files.forEach(item => {
					if(item.response){
						//当前新上传的文件
						let data = item.response.data;
						const { link } = data;
						fileUrlList.push(link);
					}else{
						//默认已有的文件
						const {url} = item;
						fileUrlList.push(url);
					}
				})
				return fileUrlList;
			},
			doBeforeModelPost: function(){
				if(!this.showEndTime){
					//根据持续时长计算结束时间
					let startTime = new Date(this.model.startTime);
					let secondsOfEndTime = startTime.setSeconds(startTime.getSeconds() + parseInt(this.duration));
					this.model.endTime = this.$u.timeFormat(secondsOfEndTime,'yyyy-mm-dd hh:MM:ss');
				}
				if(this.model.userList.length > 0){
					let userIds = this.model.userList.map(user => user.userId);
					this.model.attendees = userIds.join(',');
				}
				// if(this.getAttachFileList().length > 0){
				// 	this.model.attach = this.getAttachFileList().join(",");
				// }
			},
			repeatDayOfWeekGroupChange(e){
				this.model.repeatDayOfWeek = e.join(',');
			},
			repeatDayOfMonthGroupChange(e){
				this.model.repeatDayOfMonth = e.join(',');
			},
			isRemindChange(value) {
				this.model.isRemind = value;
			},
			isRepeatChange(value) {
				this.model.isRepeat = value;
			},
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						uni.showLoading({
							title: '提交中....'
						})
						this.doBeforeModelPost();
						let promise = this.$u.api.wechat.wechatSchedule.save(this.model);
						promise.then(res => {
							uni.hideLoading();
							uni.showModal({
								title: '提示',
								content: res.msg,
								showCancel: false,
								success: function() {
									if (res.code == 200) {
										uni.setStorageSync('refreshWecahtScheduleList', true);
										uni.navigateBack();
									}
								}
							});
						});
					} else {
						this.$u.toast('您填写的信息有误，请根据提示修正。');
					}
				});
			},
			cancel() {
				uni.navigateBack();
			},
			clearRemindTypeRelRequiredFieldProps(val,oldVal) {
				const remindTypeRelRequiredFieldProps = {
					'1': ['summary','startTime','duration','endTime','repeatType','repeatUntil'],
					'2': ['summary','startTime','repeatType','repeatUntil'],
					'3': ['summary','startTime'],
					'4': ['summary','startTime'],
					'5': ['summary','startTime','repeatType','repeatUntil']
				};
				let needResetFiledProps = [];
				if(oldVal){
					needResetFiledProps = remindTypeRelRequiredFieldProps[oldVal];
				}
				// 移除上一个提醒类型对应的form-item检验结果
				if(needResetFiledProps && needResetFiledProps.length > 0){
					this.$refs.uForm.fields.map(field => {
						if(needResetFiledProps.includes(field.prop)){
							field.resetField();
						}
					});
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.wrap {
		padding: 30rpx;
	}

	.uTagStyle {
		margin-right: 10rpx;
	}

	.scroll-Y {
		height: 200rpx;
	}

	/deep/ ::-webkit-scrollbar {
		/*滚动条整体样式*/
		width: 4px !important;
		height: 1px !important;
		overflow: auto !important;
		background: #ccc !important;
		-webkit-appearance: auto !important;
		display: block;
	}

	/deep/ ::-webkit-scrollbar-thumb {
		/*滚动条里面小方块*/
		border-radius: 10px !important;
		box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
		background: #7b7979 !important;
	}

	/deep/ ::-webkit-scrollbar-track {
		/*滚动条里面轨道*/
		background: #FFFFFF !important;
	}
</style>